package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.OrderDetailWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.common.result.ResultCode;
import org.zpmis.domain.order.qo.*;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description: 订单明细
* @author  Yang
* date: 2021-8-11
* time: 14:03:34
*/
@RestController
@RequestMapping("/order/detail")
@Slf4j
public class OrderDetailController extends BaseController{

    @Resource
    private OrderDetailWebService orderDetailWebService;

    /**
     * 添加订单明细
     * @param orderDetailQo
     * @return
     */
    @PostMapping("/addOrderDetail")
    public PlatformResult addOrderDetail(@Validated @RequestBody AddOrderDetailQo orderDetailQo){
        try {
            orderDetailWebService.addOrderDetail(orderDetailQo);
        } catch (BusinessException be) {
            log.error("[OrderDetailController]---addOrderDetail--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        }catch (Exception e) {
            log.error("[OrderDetailController]---addOrderDetail--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 修改订单明细
     * @param editOrderDetailQo
     * @return
     */
    @PostMapping("/editOrderDetail")
    public PlatformResult editOrderDetail(@Validated @RequestBody EditOrderDetailQo editOrderDetailQo){
        try {
            orderDetailWebService.editOrderDetail(editOrderDetailQo);
        } catch (BusinessException be) {
            log.error("[OrderDetailController]---editOrderDetail--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        }catch (Exception e) {
            log.error("[OrderDetailController]---editOrderDetail--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 删除订单明细
     * @param delOrderDetailQo
     * @return
     */
    @PostMapping("/delOrderDetail")
    public PlatformResult delOrderDetail(@Validated @RequestBody DelOrderDetailQo delOrderDetailQo){
        try {
            orderDetailWebService.delOrderDetail(delOrderDetailQo);
        } catch (BusinessException be) {
            log.error("[OrderDetailController]---delOrderDetail--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        }catch (Exception e) {
            log.error("[OrderDetailController]---delOrderDetail--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 根据订单id查询订单明细列表
     * @param orderDetailListQo
     * @return
     */
    @PostMapping("/orderDetailList")
    public PlatformResult orderDetailList(@Validated @RequestBody OrderDetailListQo orderDetailListQo){
        try {
            return PlatformResult.success(orderDetailWebService.orderDetailList(orderDetailListQo));
        } catch (BusinessException be) {
            log.error("[OrderDetailController]---orderDetailList--->BusinessException:",be);
            return PlatformResult.failure(be.getResultCode());
        }catch (Exception e) {
            log.error("[OrderDetailController]---orderDetailList--->Exception:",e);
            return PlatformResult.failure();
        }

    }

    /**
     * 订单明细确认收款
     * @param confirmReceiptDetailQo
     * @return
     */
    @PostMapping("/confirmCollection")
    public PlatformResult confirmCollection(@Validated @RequestBody ConfirmReceiptDetailQo confirmReceiptDetailQo){
        try {
            orderDetailWebService.confirmCollection(confirmReceiptDetailQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[OrderController]---confirmCollection--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[OrderController]---confirmCollection--->Exception:",e);
            return PlatformResult.failure(ResultCode.ERROR);
        }
    }
}
